package com.alex.controller.test;

import com.alex.pojo.User;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

@Component
public class UserConverter implements Converter<String, User> {

    @Override
    public User convert(String source) {
        if (source != null) {
            String[] vals = source.split(" ");
            if (vals != null && vals.length==2) {
                User user = new User();
                user.setName(vals[0]);
                user.setEmail(vals[1]);
                System.out.println("UserConverter: source: " + source + " -> " + user );
                return user;
            }
        }
        return null;
    }
}
